$(function () {
    // var h = $(".content-wrapper").css("min-height");
    // $(".content-wrapper").slimScroll({
    //     height: h
    // });

    $(function () {
        $('[data-toggle="tooltip"]').tooltip()
    });


    // ajax默认选项
    $.ajaxSetup({
        global: false,
        type: "POST",
        cache: false,
        dataType: "json",
        dataFilter: function (data, type) {
            if (type == "json" && data == "") {
                data = "{}";
            }
            return data;
        },
        error: function (data, status) {
            // tipper.danger(data.responseJSON.msg);
            bootbox.alert({
                message: data.responseJSON.msg,
                size: "small",
                title: "<i class='fa fa-info-circle text-yellow'></i> 提示"
            });
        }
    });

    //自定义alert
    bootbox.balert = function (msg, callback) {
        bootbox.alert({
            message: msg,
            size: "small",
            title: "<i class='fa fa-info-circle text-yellow'></i> 提示",
            callback: callback
        });
    };
    bootbox.bconfirm = function (msg, callback) {
        bootbox.confirm({
            message: msg,
            size: "small",
            title: "<i class='fa fa-question-circle text-yellow'></i> 提示",
            callback: callback
        });
    };
    bootbox.bsuccess = function (msg, callback) {
        bootbox.alert({
            message: msg,
            size: "small",
            title: "<i class='fa fa-check-circle text-green'></i> 提示",
            callback: callback
        });
    };

    // bootbox默认选项
    bootbox.setDefaults({
        "animate": false,
        "locale": "zh_CN"
    });

    //扩展jquery方法
    $.extend({
        postJsonBody: function (url, body, callback) {
            $.post({
                url: url,
                data: JSON.stringify(body),
                contentType: "application/json; charset=UTF-8",
                success: function (re) {
                    callback(re);
                }
            });
        },
        putJsonBody: function (url, body, callback) {
            $.ajax({
                url: url,
                type: "PUT",
                data: JSON.stringify(body),
                contentType: "application/json; charset=UTF-8",
                success: function (re) {
                    callback(re);
                }
            });
        },
        delete: function (url, callback) {
            $.ajax({
                url: url,
                type: "DELETE",
                success: function (re) {
                    callback(re);
                }
            });
        }
    });
});


//顶部提示条组件
window.tipper = {
    tip: function (type, content) {
        var $tip;
        if (type == "success") {
            $tip = $("<span id='tipper' class='toptip toptip-success'><span class='toptip-content'><i class='fa fa-check-circle'></i> " + content + "</span></span>");
        } else if (type == "info") {
            $tip = $("<span id='tipper' class='toptip toptip-info'><span class='toptip-content'><i class='fa fa-info-circle'></i> " + content + "</span></span>");
        } else if (type == "warning") {
            $tip = $("<span id='tipper' class='toptip toptip-warning'><span class='toptip-content'><i class='fa fa-warning'></i> " + content + "</span></span>");
        } else if (type == "danger") {
            $tip = $("<span id='tipper' class='toptip toptip-danger'><span class='toptip-content'><i class='fa fa-times-circle'></i> " + content + "</span></span>");
        }

        try {
            window.clearTimeout(window.tipTimer);
            $("#tipper").remove();
        } finally {
            $("body").prepend($tip);
            window.tipTimer = window.setTimeout(function () {
                $tip.remove();
            }, 3000);
        }
    },
    info: function (msg) {
        tipper.tip("info", msg);
    },
    success: function (msg) {
        tipper.tip("success", msg);
    },
    warning: function (msg) {
        tipper.tip("warning", msg);
    },
    danger: function (msg) {
        tipper.tip("danger", msg);
    }
};